/**
 * 
 */
package com.base.myproject.client.busi.system;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.user.client.ui.Label;

/**
 * 公司信息的录入
 * @author zgw
 *2009-10-26 下午06:14:12
 * javazgw@gmail.com
 */
public class SystemInfoPanel extends BaseJDBCPanel implements Listener<BaseEvent>{

	Button addbutton ;
	Button delbutton ;
	Button savebutton;
	BaseStore<BusiObject> store ;
	public SystemInfoPanel()
	{
		super();
		init();
	}
	public void init()
	{
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
	
	    this.add(initWeiget(),centerData);
		
		registerMainStore(store);
		registerStore(store);
		
		this.setBusino(busi);
		this.setWidth("1024px");
		this.setHeight("200px");
		setdefault();

	}
	private void setdefault()
	{
		//getStore().addDefault("busicode", busi);
	}
	public ContentPanel initWeiget() 
	{

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("icode");
		type.addField("id");
		type.addField("name");

		
		
		type.getField("id").setType(String.class);
		type.getField("name").setType(String.class);
		// type.addField("Phone");
		// type.addField("imagepath");
		StoreInfo info = new StoreInfo();
		info.setTablename("systeminfo");
		info.setSql("select * from systeminfo ");
		info.setKeyname(new String[] { "icode" });
		info.setNeedAllRow("no");
		store = new BaseStore<BusiObject>(type,info);
		
		
		ContentPanel panel = new ContentPanel();
		panel.setLayout(new BorderLayout());
		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 250);
		westData.setSplit(true);
		westData.setCollapsible(true);
		westData.setMargins(new Margins(0));
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 0, 5, 0));
//		panel.add(CreateCcodeLeftPanel(), westData);
		panel.add(CreateForm(), centerData);
		
		return panel;
		
	}
	 BaseFormPanel CreateForm()
	 {
			BaseFormPanel bfp = new BaseFormPanel(store);
			Label id_l = new Label("id");
			id_l.setWidth("50");
			Label name_l = new Label("公司名");
			name_l.setWidth("50");
			TextField<String> id_t = new TextField<String>();
			TextField<String> name_t = new TextField<String>();
			id_t.setName("id") ;
			name_t.setName("name") ;
			
			TableLayout tl = new TableLayout(4);
			tl.setWidth("600");
			bfp.setLayout(tl);
			TableData td=new TableData();
			td.setColspan(1);
		//	td.setWidth("600");
			td.setMargin(100);
			td.setPadding(5);
			td.setRowspan(1);
			bfp.add(id_l,td);
			bfp.add(id_t,td);
			bfp.add(name_l,td);
			bfp.add(name_t,td);
			
			HorizontalPanel hpanel = new HorizontalPanel();
			 addbutton = new Button("添加");
			// delbutton = new Button("删除");
			 savebutton = new Button("保存");
			
			hpanel.add(addbutton);
			//hpanel.add(delbutton);
			hpanel.add(savebutton);
			addbutton.addListener(Events.Select, this);
		//	delbutton.addListener(Events.Select, this);
			savebutton.addListener(Events.Select, this);
			bfp.add(hpanel,td);
			bfp.inited();
			return bfp;
	 }
	@Override
	public void handleEvent(BaseEvent be) {
		if(be.getSource().equals(addbutton))
		{
			if(store.getCount()<=0)
			store.addX();
			else
			{
				Info.display("提示", "没有添加此信息的权利");
			}
		}
//		else if(be.getSource().equals(delbutton))
//		{
//			basbusileftpanel.getGrid().deleterecord();
//		}
		else if(be.getSource().equals(savebutton))
		{
			store.trySave();
		}
		
	}

	
}
